package cn.ffcs.uec.staff.action;

import java.text.ParseException;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.uec.common.manager.CustomFilesManager;
import cn.ffcs.uec.organization.manager.UecOrgOrgsManager;
import cn.ffcs.uec.staff.action.bean.UecStaffInfoDetailBean;
import cn.ffcs.uec.staff.model.UecStaffInfo;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.DateUtil;
import cn.ffcs.uom.common.util.PubUtil;
import cn.ffcs.uom.common.util.StrUtil;

/**
 * 员工详细信息查看
 * 
 * @author zhanglu
 * @version Revision 1.0.0
 */
@Controller
@Scope("prototype")
public class UecStaffInfoDetailComposer extends BasePortletComposer {
	private static final long serialVersionUID = 2521981751013898398L;

	/**
	 * bean.
	 */
	private UecStaffInfoDetailBean bean = new UecStaffInfoDetailBean();

	/**
	 * 操作类型.
	 */
	private String opType = null; // 操作类型

	/**
	 * 员工信息
	 */
	private UecStaffInfo uecStaffInfo;

	private UecOrgOrgsManager uecOrgOrgsManager = (UecOrgOrgsManager) ApplicationContextUtil
			.getBean("uecOrgOrgsManager");

	private CustomFilesManager customFilesManager = (CustomFilesManager) ApplicationContextUtil
			.getBean("customFilesManager");

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);
	}

	/**
	 * window初始化.
	 * 
	 * @throws Exception
	 *             异常
	 */
	public void onCreate$uecStaffInfoDetailWindow() throws Exception {
		this.bindBean();
	}

	/**
	 * 
	 * @throws Exception
	 */
	public void bindBean() throws Exception {
		opType = StrUtil.strnull(arg.get("opType"));
		uecStaffInfo = (UecStaffInfo) arg.get("uecStaffInfo");
		if ("view".equals(opType)) {
			if (uecStaffInfo != null) {
				PubUtil.fillBeanFromPo(uecStaffInfo, this.bean);
				this.groupDataTranslationDisplay();
			}
		}
	}

	/**
	 * 数据翻译
	 * 
	 * @throws Exception
	 */
	public void groupDataTranslationDisplay() throws Exception {
		if (null != uecStaffInfo) {
			// String类型日期转Date
			this.stringTransToDate();
			// 进入电信来源
			bean.getGlbdef2().setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getGlbdef2()));
			// 专业技术职务
			bean.getTitletechpost()
					.setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getTitletechpost()));
			// 职业资格
			bean.getProf().setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getProf()));
			// 所属组织
			bean.getPkOrg().setValue(uecOrgOrgsManager.getUecOrgOrgsNameByPkOrg(uecStaffInfo.getPkOrg()));
			// 人力资源组织
			bean.getPkHrorg().setValue(uecOrgOrgsManager.getUecOrgOrgsNameByPkOrg(uecStaffInfo.getPkHrorg()));
			// 民族
			bean.getNationality().setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getNationality()));
			// 婚姻状况
			bean.getMarital().setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getMarital()));
			// 健康状况
			bean.getHealth().setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getHealth()));
			// 政治面貌
			bean.getPolity().setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getPolity()));
			// 学历
			bean.getEdu().setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getEdu()));
			// 学位
			bean.getPkDegree().setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getPkDegree()));
			// 户口性质
			bean.getCharacterrpr()
					.setValue(customFilesManager.findCustomFilesByPkdefdoc(uecStaffInfo.getCharacterrpr()));
			// 证件类型
			if (null != uecStaffInfo.getIdtype()) {
				Long idtype = uecStaffInfo.getIdtype();
				if (0L == idtype) {
					bean.getIdtype().setValue("身份证");
				} else {
					bean.getIdtype().setValue("");
				}
			}
			// 性别
			if (null != uecStaffInfo.getSex()) {
				Long sex = uecStaffInfo.getSex();
				if (sex == 1) {
					bean.getSex().setValue("男");
				} else if (sex == 2) {
					bean.getSex().setValue("女");
				} else {
					bean.getSex().setValue("");
				}
			}
			// 是否是历史成员
			if (null != uecStaffInfo.getIshiskeypsn()) {
				String ishiskeypsn = uecStaffInfo.getIshiskeypsn();
				if ("Y".equals(ishiskeypsn)) {
					bean.getIshiskeypsn().setValue("是");
				} else if ("N".equals(ishiskeypsn)) {
					bean.getIshiskeypsn().setValue("否");
				}
			}
			// 是否是门店营业员
			if (null != uecStaffInfo.getIsshopassist()) {
				String isshopassist = uecStaffInfo.getIsshopassist();
				if ("Y".equals(isshopassist)) {
					bean.getIsshopassist().setValue("是");
				} else if ("N".equals(isshopassist)) {
					bean.getIsshopassist().setValue("否");
				}
			}
			// 是否承包经营个人
			if (null != uecStaffInfo.getGlbdef14()) {
				String glbdef14 = uecStaffInfo.getGlbdef14();
				if ("Y".equals(glbdef14)) {
					bean.getGlbdef14().setValue("是");
				} else if ("N".equals(glbdef14)) {
					bean.getGlbdef14().setValue("否");
				}
			}
		}
	}

	/**
	 * 将String类型的时间转换成Date类型
	 * 
	 * @throws ParseException
	 */
	public void stringTransToDate() throws ParseException {
		// 出生日期
		if (!StrUtil.isNullOrEmpty(uecStaffInfo.getBirthdate())) {
			bean.getBirthdate().setValue(DateUtil.patternStrToDate(uecStaffInfo.getBirthdate()));
		}
		// 入党(团)日期
		if (!StrUtil.isNullOrEmpty(uecStaffInfo.getJoinpolitydate())) {
			bean.getJoinpolitydate().setValue(DateUtil.patternStrToDate(uecStaffInfo.getJoinpolitydate()));
		}
		// 身故日期
		if (!StrUtil.isNullOrEmpty(uecStaffInfo.getDieDate())) {
			bean.getDieDate().setValue(DateUtil.patternStrToDate(uecStaffInfo.getDieDate()));
		}
		// 参加工作日期
		if (!StrUtil.isNullOrEmpty(uecStaffInfo.getJoinworkdate())) {
			bean.getJoinworkdate().setValue(DateUtil.patternStrToDate(uecStaffInfo.getJoinworkdate()));
		}
		// 离退休日期
		if (!StrUtil.isNullOrEmpty(uecStaffInfo.getRetiredate())) {
			bean.getRetiredate().setValue(DateUtil.patternStrToDate(uecStaffInfo.getRetiredate()));
		}
		// 预计退休日期
		if (!StrUtil.isNullOrEmpty(uecStaffInfo.getGlbdef15())) {
			bean.getGlbdef15().setValue(DateUtil.patternStrToDate(uecStaffInfo.getGlbdef15()));
		}
		// 进入电信系统日期
		if (!StrUtil.isNullOrEmpty(uecStaffInfo.getGlbdef3())) {
			bean.getGlbdef3().setValue(DateUtil.patternStrToDate(uecStaffInfo.getGlbdef3()));
		}
	}
}
